//==========================================================================
// Copyright (c) 2000-2008,  Elastos, Inc.  All Rights Reserved.
//==========================================================================

#ifndef __CDeviceEventManager_H__
#define __CDeviceEventManager_H__

#define _NO_CDEVICEEVENTMANAGER_CLASSOBJECT_
#define _NO_INCLIST
#include <elasys_server.h>
#define __NO_LINKNODE_CONSTRUCTOR
#include <linknode.h>

#include "stub.h"
#include "_CDeviceEventManager.h"

#define EVENT_HASH_LENGTH 128
#define EVENT_HASH_INDEX(eventnum) (eventnum % EVENT_HASH_LENGTH)

//typedef struct EveHandler {
//    Int32 nOrder;
//    IDeviceEventDispatcher *pEveDelegate;
//    struct EveHandler *pNextHandler;
//} EveHandler, *PEveHandler;

//typedef struct EventInfo : public DLinkNode {
//    UInt32 uEventNum;
//    PEveHandler pHandlerList;
//} EventInfo, *PEventInfo;

typedef struct DeviceEventDispatcher : public DLinkNode {
    Int32 uEventNum;
    IDeviceEventDispatcher *pDeviceEventDispatcher;
} DeviceEventDispatcher, *PDeviceEventDispatcher;

//typedef struct EventNode : public DLinkNode {
//    UInt32 uEventNum;
//    union {
//        struct {
//            UInt32 uNum;
//            EmIsrParameter isrpm;
//        } ipm;
//        MemoryBuf eventData;
//    }um;
//    Boolean bIsrParameter;
//}EventNode, *PEventNode;

typedef struct DeviceEventNodeBase : public DLinkNode
{
    Int32  uEventNum;
    Boolean  bIsrParameter;
}DeviceEventNodeBase, *PDeviceEventNodeBase;

typedef struct DeviceEventNode : DeviceEventNodeBase
{
    PMemoryBuf peventData;
}DeviceEventNode, *PDeviceEventNode;

typedef struct DeviceEventIsrNode : DeviceEventNodeBase
{
    Int32 uNum;
    EmIsrParameter isrpm;
}DeviceEventIsrNode, *PDeviceEventIsrNode;

typedef struct DeviceEventIsrBlockNode : public DLinkNode
{
    DeviceEventIsrNode deviceEventIsrNode;
}DeviceEventIsrBlockNode, *PDeviceEventIsrBlockNode;

class CDeviceEventManager : public _CDeviceEventManager
{
public:
    CARAPI SendEvent(
        /* [in] */ Int32 uEventNum,
        /* [in] */ const MemoryBuf & ebEventData);

    CARAPI PostEvent(
        /* [in] */ Int32 uEventNum,
//        /* [in] */ Int32 nPriority,
        /* [in] */ const MemoryBuf & ebEventData);

    CARAPI AddEventHandler(
        /* [in] */ Int32 uEventNum,
//        /* [in] */ Int32 nOrder,
        /* [in] */ IDeviceEventDispatcher * pDeviceEventDispatcher);

    CARAPI RemoveEventHandler(
        /* [in] */ Int32 uEventNum,
        /* [in] */ IDeviceEventDispatcher * pDeviceEventDispatcher);

    ECode Initialize();

    ~CDeviceEventManager();

private:
    // TODO: Add your private member variables here.
};

#endif // __CDeviceEventManager_H__
